package com.travel.server.manager.impl.command.project;

import com.travel.server.manager.dto.request.project.UpdateProjectOtherInfoRequest;
import com.travel.server.manager.dto.response.UpdateProjectOtherInfoResponse;
import com.travel.server.manager.impl.command.AbstractCommand;
import com.travel.server.manager.impl.dal.ProjectDal;
import com.travel.server.manager.model.ProjectInfo;
import com.travel.server.manager.model.UserInfo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.Date;

/**
 * @Author: LiZhenhui
 * @Date: 2018/11/1 10:18
 * @Desc:
 */
@Component
@Slf4j
public class UpdateProjectOtherInfoCommand extends AbstractCommand<UpdateProjectOtherInfoRequest, UpdateProjectOtherInfoResponse> {

    @Autowired
    private ProjectDal projectDal;

    @Override
    protected void checkInput(UpdateProjectOtherInfoRequest request) {

    }

    @Override
    public UpdateProjectOtherInfoResponse handle(UpdateProjectOtherInfoRequest request) {
        UserInfo userInfo = getUserInfo();
        Date now = new Date();

        ProjectInfo projectInfo = projectDal.getProjectInfo(request.getId(), userInfo);
        projectInfo.setCostExplains(request.getExplains());
        projectInfo.setAttention(request.getAttention());
        projectInfo.setUpdateTime(now);
        projectInfo.setUpdateBy(userInfo.getName());

        projectDal.insertOrUpdate(projectInfo);

        UpdateProjectOtherInfoResponse response = new UpdateProjectOtherInfoResponse();
        response.setId(projectInfo.getId());

        return response;
    }
}
